package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.EthToken;
import com.cp.admin.modular.system.service.IEthTokenService;

/**
 * 系统账户管理控制器
 *
 * @author fengshuonan
 * @Date 2020-03-12 09:01:14
 */
@Controller
@RequestMapping("/ethToken")
public class EthTokenController extends BaseController {

    private String PREFIX = "/system/ethToken/";

    @Autowired
    private IEthTokenService ethTokenService;

    /**
     * 跳转到系统账户管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "ethToken.html";
    }

    /**
     * 跳转到添加系统账户管理
     */
    @RequestMapping("/ethToken_add")
    public String ethTokenAdd() {
        return PREFIX + "ethToken_add.html";
    }

    /**
     * 跳转到修改系统账户管理
     */
    @RequestMapping("/ethToken_update/{ethTokenId}")
    public String ethTokenUpdate(@PathVariable Long ethTokenId, Model model) {
        EthToken ethToken = ethTokenService.selectById(ethTokenId);
        model.addAttribute("item",ethToken);
        LogObjectHolder.me().set(ethToken);
        return PREFIX + "ethToken_edit.html";
    }

    /**
     * 获取系统账户管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return ethTokenService.selectList(null);
    }

    /**
     * 新增系统账户管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(EthToken ethToken) {
        ethTokenService.insert(ethToken);
        return SUCCESS_TIP;
    }

    /**
     * 删除系统账户管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long ethTokenId) {
        ethTokenService.deleteById(ethTokenId);
        return SUCCESS_TIP;
    }

    /**
     * 修改系统账户管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(EthToken ethToken) {
        ethTokenService.updateById(ethToken);
        return SUCCESS_TIP;
    }

    /**
     * 系统账户管理详情
     */
    @RequestMapping(value = "/detail/{ethTokenId}")
    @ResponseBody
    public Object detail(@PathVariable("ethTokenId") Long ethTokenId) {
        return ethTokenService.selectById(ethTokenId);
    }
}
